﻿<?php
Class Answer extends CI_Model
{
	function get_answer($question_id)
	{
		$this -> db -> select('answer_id, content');
		$this -> db -> from('answer');
		$this -> db -> where('question_id  = ' . $question_id . ' order by `tdc_answer`.`order`');
		$this -> db -> limit(4);

		$query = $this -> db -> get();

		if($query -> num_rows() == 4)
		{
			return $query->result();
		}
		else
		{
			return false;
		}	
	}
	
	function insert_answer($content, $order, $question_id)
	{
		$data = array(
			'content' => $content,
			'order' => $order,
			'question_id' => $question_id
		);
		
		$this -> db -> insert('answer', $data);
		
		//recheck whether answer is inserted successfully
		if($this->db->affected_rows() == 1)
			return true;
		else
			return false;
	}
	
	function update_answer($content, $answer_id)
	{
		$data = array(
			'content' => $content
		);
		
		$this -> db -> where('answer_id', $answer_id);
		$this -> db -> update('answer', $data);
		
		//recheck whether answer is inserted successfully
		//if($this->db->affected_rows() == 1)
			return true;
		//else
		//	return false;
	}
}